package com.xinqi.modules.course.image.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.course.image.dto.req.CourseImageCreateDTO;
import com.xinqi.modules.course.image.dto.req.CourseImageQueryDTO;
import com.xinqi.modules.course.image.dto.req.CourseImageUpdateDTO;
import com.xinqi.modules.course.image.dto.rsp.CourseImageResultDTO;
import com.xinqi.modules.course.image.service.CourseImageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * 课程背景封面图表APP控制层
 *
 * @author: system
 * @date: 2023/03/22
 */
@Tag(name = "App-课程背景", description = "课程背景")
@RestController
@RequestMapping("/app/course-image")
@RequiredArgsConstructor
public class CourseImageAppController {
    private final CourseImageService courseImageService;

    /**
     * 课程背景封面图表-分页
     */
    @Operation(summary = "课程背景封面图表-分页")
    @GetMapping("/page")
    public R<PageInfo<CourseImageResultDTO>> page(@ParameterObject CourseImageQueryDTO dto) {
        PageInfo<CourseImageResultDTO> page = courseImageService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 课程背景封面图表-详情
     */
    @Operation(summary = "课程背景封面图表-详情")
    @GetMapping("/{id}")
    public R<CourseImageResultDTO> findById(@PathVariable("id") Long id) {
        CourseImageResultDTO dto = courseImageService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增课程背景封面图表
     */
    @Operation(summary = "新增课程背景封面图表")
    @PostMapping
    public R<Long> insert(@RequestBody CourseImageCreateDTO dto) {
        return R.data(courseImageService.insert(dto));
    }

    /**
     * 修改课程背景封面图表
     */
    @Operation(summary = "修改课程背景封面图表")
    @PutMapping("/{id}")
    public R<Boolean> update(@PathVariable("id") Long id, @RequestBody CourseImageUpdateDTO dto) {
        dto.setId(id);
        return R.data(courseImageService.updateById(dto));
    }

    /**
     * 删除课程背景封面图表
     */
    @Operation(summary = "删除课程背景封面图表")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.data(courseImageService.deleteById(id));
    }

}
